package com.example.quartz.config;

import com.example.quartz.HelloJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description : Quartz 配置类
 * @Author : Bruce Lee
 * @CreateTime : 2024/2/6
 */

@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail jobDetail() {
        JobDetail job = JobBuilder.newJob(HelloJob.class)
                .withIdentity("job2", "group1")
                .usingJobData("name", "Quartz!")
                .storeDurably()
                .build();

        return job;
    }

    @Bean
    public Trigger trigger() {
        CronTrigger trigger = TriggerBuilder.newTrigger()
                .forJob(jobDetail())
                .withIdentity("trigger2", "group1")
                .withSchedule(CronScheduleBuilder
                        .cronSchedule("* * * * * ?")
                        .withMisfireHandlingInstructionFireAndProceed()
                ).build();

        return trigger;
    }
}
